﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        #container {
            width: 400px;
            height: 200px;
            border: 1px solid #eee;
            overflow: hidden;
        }

        #menu {
            padding: 0px;
            margin: 0 auto;
            height: 40px;
            line-height: 40px;
            border-bottom: 1px solid #ddd;
            padding: 0px;
        }

            #menu ul li, #menu ul li a {
                display: inline-block;
                float: left;
                width: 100px;
                text-align: center;
            }

        a {
            text-decoration: none;
            margin: 0px;
        }

        .mod {
            width: 400px;
            height: 160px;
            display: none;
        }

        .select {
            background-color: #eee;
        }
    </style>
</head>
<body>
    <div id="container">
        <div id="menu">
            <ul>
                <li class="select"><a href="">item1</a></li>
                <li><a href="">item2</a></li>
                <li><a href="">item3</a></li>
                <li><a href="">item4</a></li>
            </ul>
        </div>
        <div id="mod_content">
            <div class="mod" style="display:block;">item1</div>
            <div class="mod">item2</div>
            <div class="mod">item3</div>
            <div class="mod">item4</div>
        </div>
    </div>
    <script type="text/javascript">
        window.onload = function () {
            var timer = null;
            var menu = document.getElementById('menu');
            var mod_content = document.getElementById('mod_content');
            var menu_li = menu.getElementsByTagName('li');
            var mod = mod_content.getElementsByTagName('div');
            for (var i = 0 ; i < menu_li.length  ; i++) {
                menu_li[i].ind = i;
                menu_li[i].onmouseover = function () {
                    clearInterval(timer);
                    showTab(this);
                };
                menu_li[i].onmouseout = function () {
                    autoPlay(this.ind);
                }
            }
            autoPlay(0);
            function autoPlay(index) {
                clearInterval(timer);
                timer = setInterval(function () {
                    showTab(menu_li[index]);
                    index++;
                    if (index >= menu_li.length) {
                        index = 0;
                    }
                }, 1000);
            }
            function showTab(_this) {
                for (var i = 0; i < menu_li.length; i++) {
                    menu_li[i].className = '';
                    mod[i].style.display = 'none';
                };
                _this.className = 'select';
                mod[_this.ind].style.display = 'block';
            }
        };

    </script>
</body>
</html>
